#include "pch.h"
#include "Metadata.h"


Metadata::Metadata() {
    metadaArray = {
        FlvMetaItem(L"duration", AMFType::Number, NULL),          //0
        FlvMetaItem(L"width", AMFType::Number, NULL),             //1
        FlvMetaItem(L"height", AMFType::Number, NULL),
        FlvMetaItem(L"videodatarate", AMFType::Number, NULL),
        FlvMetaItem(L"framerate", AMFType::Number, NULL),
        FlvMetaItem(L"videocodecid", AMFType::Number, NULL),      //5
        FlvMetaItem(L"audiosamplerate", AMFType::Number, NULL),
        FlvMetaItem(L"audiosamplesize", AMFType::Number, NULL),
        FlvMetaItem(L"stereo", AMFType::Boolean, NULL),
        FlvMetaItem(L"audiocodecid", AMFType::Number, NULL),
        FlvMetaItem(L"filesize", AMFType::Number, NULL),          //10
        FlvMetaItem(L"lasttimestamp", AMFType::Number, NULL),
        FlvMetaItem(L"lastkeyframetimestamp", AMFType::Number, NULL),
        FlvMetaItem(L"audiodelay", AMFType::Number, NULL),
        FlvMetaItem(L"canSeekToEnd", AMFType::Boolean, NULL),
        FlvMetaItem(L"creationdate", AMFType::Date, NULL),        //15
        FlvMetaItem(L"metadatacreator", AMFType::String, NULL)    //16
    };
}


Metadata::~Metadata() {
}


double Metadata::Duration() {
    return metadaArray[0].doubleValue;
}

void Metadata::Duration(double duration) {
    metadaArray[0].doubleValue = duration;
}

int Metadata::Width() {
    return metadaArray[1].intValue;
}

void Metadata::Width(int width) {
    metadaArray[1].intValue = width;
}

int Metadata::Height() {
    return metadaArray[2].intValue;
}

void Metadata::Height(int height) {
    metadaArray[2].intValue = height;
}

int Metadata::VideoDataRate() {
    return metadaArray[3].intValue;
}

void Metadata::VideoDataRate(int videoDetaRate) {
    metadaArray[3].intValue = videoDetaRate;
}

double Metadata::FrameRate() {
    return metadaArray[4].doubleValue;
}

void Metadata::FrameRate(double frameRate) {
    metadaArray[4].doubleValue = frameRate;
}

int Metadata::VideoCodeCID() {
    return metadaArray[5].intValue;
}

void Metadata::VideoCodeCID(int videoCodeCID) {
    metadaArray[5].intValue = videoCodeCID;
}

int Metadata::AudioSampleRate() {
    return metadaArray[6].intValue;
}

void Metadata::AudioSampleRate(int audioSampleRate) {
    metadaArray[6].intValue = audioSampleRate;
}

int Metadata::AudioSampleSize() {
    return metadaArray[7].intValue;
}

void Metadata::AudioSampleSize(int audioSampleSize) {
    metadaArray[7].intValue = audioSampleSize;
}

bool Metadata::Stereo() {
    return metadaArray[8].boolValue;
}

void Metadata::Stereo(bool stereo) {
    metadaArray[8].boolValue = stereo;
}

int Metadata::AudioCodeCID() {
    return metadaArray[9].intValue;
}

void Metadata::AudioCodeCID(int audioCodeCID) {
    metadaArray[9].intValue = audioCodeCID;
}

int Metadata::FileSize() {
    return metadaArray[10].intValue;
}

void Metadata::FileSize(int fileSize) {
    metadaArray[10].intValue = fileSize;
}

double Metadata::LastTimesStamp() {
    return metadaArray[11].doubleValue;
}

void Metadata::LastTimesStamp(double lastTimesStamp) {
    metadaArray[11].doubleValue = lastTimesStamp;
}

double Metadata::LastKeyFrameTimeStamp() {
    return metadaArray[12].doubleValue;
}

void Metadata::LastKeyFrameTimeStamp(double lastKeyFrameTimeStamp) {
    metadaArray[12].doubleValue = lastKeyFrameTimeStamp;
}

int Metadata::AudioDelay() {
    return metadaArray[13].intValue;
}

void Metadata::AudioDelay(int audioDelay) {
    metadaArray[13].intValue = audioDelay;
}

bool Metadata::CanSeekToEnd() {
    return metadaArray[14].boolValue;
}

void Metadata::CanSeekToEnd(bool canSeekToEnd) {
    metadaArray[14].boolValue = canSeekToEnd;
}

std::wstring Metadata::CreationDate() {
    return metadaArray[15].strValue;
}

void Metadata::CreationDate(std::wstring creationDate) {
    metadaArray[15].strValue = creationDate;
}

std::wstring Metadata::MetaDataCreator() {
    return metadaArray[16].strValue;
}

void Metadata::MetaDataCreator(std::wstring metaDataCreator) {
    metadaArray[16].strValue = metaDataCreator;
}

Byte Metadata::Meta_1[410] = {
    0x46, 0x4C, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0A, 0x6F, 0x6E, 0x4D, 0x65, 0x74,
    0x61, 0x44, 0x61, 0x74, 0x61, 0x08, 0x00, 0x00, 0x00, 0x12, 0x00, 0x08, 0x64, 0x75, 0x72, 0x61,
    0x74, 0x69, 0x6F, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x77,
    0x69, 0x64, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x68,
    0x65, 0x69, 0x67, 0x68, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D,
    0x76, 0x69, 0x64, 0x65, 0x6F, 0x64, 0x61, 0x74, 0x61, 0x72, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x66, 0x72, 0x61, 0x6D, 0x65, 0x72, 0x61, 0x74,
    0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x76, 0x69, 0x64, 0x65,
    0x6F, 0x63, 0x6F, 0x64, 0x65, 0x63, 0x69, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x0F, 0x61, 0x75, 0x64, 0x69, 0x6F, 0x73, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x72, 0x61,
    0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x61, 0x75, 0x64,
    0x69, 0x6F, 0x73, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x73, 0x69, 0x7A, 0x65, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x73, 0x74, 0x65, 0x72, 0x65, 0x6F, 0x01, 0x00, 0x00,
    0x0C, 0x61, 0x75, 0x64, 0x69, 0x6F, 0x63, 0x6F, 0x64, 0x65, 0x63, 0x69, 0x64, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x66, 0x69, 0x6C, 0x65, 0x73, 0x69, 0x7A, 0x65,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x6C, 0x61, 0x73, 0x74, 0x74,
    0x69, 0x6D, 0x65, 0x73, 0x74, 0x61, 0x6D, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x15, 0x6C, 0x61, 0x73, 0x74, 0x6B, 0x65, 0x79, 0x66, 0x72, 0x61, 0x6D, 0x65, 0x74,
    0x69, 0x6D, 0x65, 0x73, 0x74, 0x61, 0x6D, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x0A, 0x61, 0x75, 0x64, 0x69, 0x6F, 0x64, 0x65, 0x6C, 0x61, 0x79, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x63, 0x61, 0x6E, 0x53, 0x65, 0x65, 0x6B, 0x54,
    0x6F, 0x45, 0x6E, 0x64, 0x01, 0x00, 0x00, 0x0C, 0x63, 0x72, 0x65, 0x61, 0x74, 0x69, 0x6F, 0x6E,
    0x64, 0x61, 0x74, 0x65, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x6D, 0x65, 0x74, 0x61, 0x64, 0x61,
    0x74, 0x61, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6F, 0x72, 0x02
};

Byte Metadata::Meta_2[] = {
    0x00, 0x09, 0x6B, 0x65, 0x79, 0x66, 0x72, 0x61, 0x6D, 0x65, 0x73, 0x03, 0x00, 0x0D, 0x66, 0x69,
    0x6C, 0x65, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x0A
};

Byte Metadata::Meta_3[] = {
    0x00, 0x05, 0x74, 0x69, 0x6D, 0x65, 0x73, 0x0A
};

Byte Metadata::Meta_4[] = {
    0x00, 0x00, 0x09, 0x00, 0x00, 0x09
};